<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let str = 'abcdaAg'
        // str = str.replace(/a|c/gi, function (item) {
        //     console.log(item)
        //     return `<span style='color:red'>${item}</span>`
        // })
        // document.body.innerHTML = str

        // 需求：把a 或 c找到，替换成大写的
        // let str = "abcdgdc";
        // str = str.replace(/a|c/gi, function (item) {
        //     return item.toUpperCase()
        // })
        // console.log(str)

        function highLinght(str, keyword) {
            const reg = new RegExp(keyword, 'gi')
            return str.replace(reg, function (item) {
                return `<span style='color:red'>${item}</span>`
            })
        }
        console.log(highLinght('abacdag', 'a'));
        console.log(highLinght('awedfgcd', 'a'));
    </script>
</body>

</html>